class UserSysController < ApplicationController

 def index
    session[:index_page] = params[:page] == nil ? nil : params[:page]
    @filterrific = initialize_filterrific(UserSys,params[:filterrific]) or return
    @user_syss = @filterrific.find.page(params[:page]).order(login: :desc)
 end

 def destroy
   @user_sys = UserSys.find(params[:id])
   @user_sys.destroy
   redirect_to user_sys_path(page: session[:index_page]), notice: "删除成功"
 end

 def new
   @user_sys = UserSys.new()
 end

 def create
     @user_sys = UserSys.new(user_sys_params)
     father_id=params[:father_id]
     sectinos_name=params[:father_section_name]
     @user_sys.sections_id=father_id
     @user_sys.sectinos_name=sectinos_name
     if @user_sys.save
       redirect_to user_sys_path(page: session[:index_page]), notice: "新增成功"
       return
     else
       redirect_to user_sys_path(page: session[:index_page]), notice: "新增失败"
       return
     end
 end


 def show

   login = params[:login]
   flag = params[:flag]

   @user_sys = UserSys.find_by_login(login)
   if @user_sys!=nil
      if flag=="N"
        result = 'ok'
      elsif flag=="E"
        name = params[:name]
        user_id = params[:user_id]

        result = 'ok' + ',' +  user_id.to_s + ','  +  login + ',' + name
      end
   else
     result = 'no'
   end
   render :text=>result
 end


 def user_sys_add
   @user_sys = UserSys.find(params[:id])
   if@user_sys.update(user_sys_params)
     redirect_to user_sys_path(page: session[:index_page]), notice: "修改成功"
     return
   else
     redirect_to user_sys_path(page: session[:index_page]), notice: "修改失败"
     return
   end
 end


 def user_sys_params
   params.require(:user_sys).permit!
 end


end
